
const mixinElli = {
  props: {
    text: {
      type: null,
      default: ''
    }
  },
  computed: {
    showText () {
      let showText = ''
      if (Array.isArray(this.text)) {
        for (let i = 0; i < this.text.length; i = i + 1) {
          if (i < this.text.length - 1) {
            showText += `${this.text[i]}、`
          } else {
            showText += `${this.text[i]}`
          }
        }
      } else {
        showText = this.text
      }
      return showText
    }
  },
  data () {
    return {
      isoverflow: false
    }
  },
  watch: {
    showText: {
      handler () {
        const vm = this
        vm.$nextTick(() => {
          vm.judgeWidth()
        })
      },
      immediate: true
    }
  },
  mounted () {
    const vm = this
    // 页面加载完成执行和屏幕变化执行 缺一不可
    vm.$nextTick(() => {
      window.addEventListener('resize', () => {
        vm.judgeWidth()
      })
    })
  },
  methods: {
    judgeWidth () {
      const vm = this
      if (!vm.$refs.content) return
      const { scrollHeight } = vm.$refs.content
      const { clientHeight } = vm.$refs.content
      // 用等号所有都会出现提示，没有等号多行省略有问题
      if (scrollHeight - clientHeight >= clientHeight || clientHeight < scrollHeight) {
        vm.isoverflow = true
      } else {
        vm.isoverflow = false
      }
    }
  }
}

export {
  mixinElli
}
